package io.renren.modules.generator.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.modules.generator.dao.DictionaryDao;
import io.renren.modules.generator.entity.DictionaryEntity;
import io.renren.modules.generator.service.DictionaryService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("dictionaryService")
public class DictionaryServiceImpl extends ServiceImpl<DictionaryDao, DictionaryEntity> implements DictionaryService {

    @Autowired
    private DictionaryDao dictionaryDao;
    @Override
    public List<DictionaryEntity> queryPage(Map<String, Object> params) {
       /* String type = (String)params.get("type");
        String code = (String)params.get("code");
        String name = (String) params.get("name");
        String status = (String) params.get("status");

        Page<DictionaryEntity> page = this.selectPage(
                new Query<DictionaryEntity>(params).getPage(),
                new EntityWrapper<DictionaryEntity>()
                        .like(StringUtils.isNotBlank(type),"type",type)
                        .like(StringUtils.isNotBlank(code),"code",code)
                        .like(StringUtils.isNotBlank(name),"name",name)
                        .eq(StringUtils.isNotBlank(status),"status",status)
                        .orderBy(true,"id",false)
        );*/


        return dictionaryDao.queryPage(params);
    }

    @Override
    public int queryPageTotal(Map<String, Object> params) {

        return dictionaryDao.queryPageTotal(params);
    }

    @Override
    public List<DictionaryEntity> queryByType(String[] type) {
        List<DictionaryEntity> entities = this.selectList(new EntityWrapper<DictionaryEntity>()
                .in(type.length > 0, "type", type)
        .eq(true,"status",true)
        .orderBy(true,"order_number",false));

        return entities;
    }

    @Override
    public List<DictionaryEntity> queryByType(String type) {
        return this.selectList(new EntityWrapper<DictionaryEntity>().eq(StringUtils.isNotBlank(type),"type", type));
    }

    @Override
    public void updateStatusByIds(List<Integer> list) {
        dictionaryDao.updateStatusByIds(list);
    }

    @Override
    public DictionaryEntity queryEntityByCode(String code) {
        return this.selectOne(new EntityWrapper<DictionaryEntity>().eq(StringUtils.isNotBlank(code),"code",code));
    }

    @Override
    public List<String> queryAllTypeList() {
        return dictionaryDao.queryAllTypeList();
    }

}
